home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
013
/
chkdir.arc
/
CHKDIR.MAC
< prev
Wrap
Text File
|
1985-03-29
|
12KB
|
362 lines
$define(tag,$$segment(@1,$$index(@1,=)+1))#
/* CHKDIR - Report on directory status.
BY: Thom Henderson
DESCRIPTION:
Prints a report similar to that produced by CHKDSK, but
pertaining to the current or named directory. Disk allocation
errors are NOT (repeat, NOT) fixed.
INSTRUCTIONS:
Invoke this program with a statement of the form:
CHKDIR [d:][path]
LANGUAGE:
Computer Innovations C86
SPECIAL NOTES:
This program should be compiled and linked
using the "small model".
*/
#include <stdio.h>
struct fds /* file data structure */
{ char dummy[21]; /* reserved for dos */
unsigned char att; /* returned attribute */
unsigned time;
unsigned date;
long size; /* size of file */
unsigned char name[13]; /* string containing the filename */
int first; /* true during first search */
};
char srchname[200] = 0; /* search template */
long room; /* total room on disk */
long roomleft; /* room left on disk */
/* file grouping parameters:
files are grouped in the following categories:
0 anything in a subdirectory
1 all files of whatever kind
2 all user files
3 all read only user files
4 all hidden or system files
5 all normal subdirectories
6 all hidden or system subdirectories
Each group contains the following parts:
0 everything
1 everything not backed up
2 everything backed up
*/
#define ngrps 7 /* number of file groups */
long size[ngrps][3] = 0; /* bytes in each group */
int num[ngrps][3] = 0; /* files in each group */
/* option flags */
int subsrch = 0; /* true if looking in subdirs */
int subsep = 1; /* true if subdir files not added */
int reptype = 0; /* which part to report */
main(an,arg) /* report on directory status */
int an; /* number of arguments */
char *arg[]; /* pointers to same */
{
int a; /* argument index */
char *ap; /* argument pointer */
for(a=1; a<an; a++) /* scan each arg */
{ ap = arg[a]; /* get a pointer to it */
if(*ap=='-' || *ap=='/') /* if an option marker */
{ while(*++ap) /* then scan the marks */
{ switch(tolower(*ap))/* and act on them */
{
case 'a':
subsep = 0;
case 's':
subsrch = 1;
break;
case 'c':
reptype = 1;
break;
case 'b':
reptype = 2;
break;
default:
usage();
}
}
}
else /* else assume it is a path */
{ if(*srchname) /* watch out for multiples */
usage();
strcpy(srchname,ap); /* store name in search template */
}
}
collect(); /* collect the data */
volume(); /* report on volume */
disk(); /* report on disk */
memory(); /* report on memory */
return 0; /* no error we know of */
}
usage() /* an error in usage */
{ printf("CHKDIR, Version $tag(
TED_VERSION DB =1.43), created on $tag(
TED_DATE DB =10/17/84) at $tag(
TED_TIME DB =10:31:29)\n");
printf("(C)COPYRIGHT 1984 by System Enhancement Associates; may be\n");
printf(" freely distributed in its original, unmodified form.\n\n");
printf("If you like this program and find it useful,\n");
printf("please send five dollars to:\n\n");
printf(" System Enhancement Associates\n");
printf(" 12 Franklin Avenue\n");
printf(" Clifton, NJ 07011\n");
printf(" (201) 694-4710\n\n");
printf("usage: chkdir [-sacb] [d:][path]\n");
printf(" -s = search subdirectories\n");
printf(" -a = add subdirectory files to report\n");
printf(" -c = report only on files not backed up\n");
printf(" -b = report only on files backed up\n");
printf(" -h = print this list\n");
exit(1);
}
volume() /* report on volume */
{
struct fds vd; /* volume data structure */
if(volname(&vd)) /* if we have a volume */
{ printf("Volume %s, created ",vd.name);
pdate(vd.date); ptime(vd.time);
printf("\n");
}
}
disk() /* report on disk */
{
static char *type[] = /* report types */
{ "all files",
"files which are not backed up",
"files which have been backed up"
};
static char *name[] = /* group names */
{ "files in subdirectories",
"files",
"user files",
"read only user files",
"hidden or system files",
"subdirectories",
"hidden or system subdirectories"
};
int g; /* group index */
char *dir; /* pointer to directory name */
char *gcdir(); /* gets name of current directory */
dir = *srchname ? srchname : gcdir("");
printf("Report on %s for %s\n\n",type[reptype],dir);
printf("%9ld bytes total disk space\n",room);
if(num[0][reptype])
printf("%9ld bytes in %d files in %d directories\n",
size[0][reptype],num[0][reptype],num[5][0]);
for(g=1; g<ngrps; g++)
if(num[g][reptype])
printf("%9ld bytes in %d %s\n",
size[g][reptype],num[g][reptype],name[g]);
printf("%9ld bytes available on disk\n\n",roomleft);
}
collect() /* collect our data */
{
struct {int ax,bx,cx,dx,si,di,ds,es;} reg;
reg.ax = (0x36 << 8); /* get disk free space */
if(srchname[1]==':') /* if path includes a drive */
reg.dx = tolower(srchname[0])-'a'+1;
else reg.dx = 0; /* else default drive */
sysint21(®,®); /* DOS call */
if(reg.ax==0xffff)
abort("%c: is an invalid drive",srchname[0]);
room = (long)reg.dx * (long)reg.cx * (long)reg.ax;
roomleft = (long)reg.bx * (long)reg.cx * (long)reg.ax;
fcollect(srchname,0); /* collect the file data */
}
fcollect(path,sub) /* collect data on directory */
char *path; /* name of directory */
int sub; /* true if in a subdirectory */
{
char pbuf[200]; /* modified path buffer */
char sbuf[200]; /* subdirectory path buffer */
struct fds fd; /* file data structure */
int g; /* group index */
char *makepath(); /* path name fixer */
makepath(pbuf,path,"*.*"); /* make a search template */
fd.first = 1; /* note start of a search */
while(filedir(&fd,pbuf)) /* while we have files */
{ if(fd.att&0x10) /* if a subdirectory */
{ if(*fd.name=='.') /* if a phony directory */
continue; /* then do not add it in */
if(subsrch) /* if we are searching subs */
fcollect(makepath(sbuf,path,fd.name),subsep);
}
if(sub) /* if in a subdirectory */
addfile(&fd,0); /* then add to subdir file group */
else /* else add in wherever needed */
{ addfile(&fd,1); /* add to total */
if(fd.att&0x10) /* subdirectory */
{ if(fd.att&0x06) /* hidden or system */
addfile(&fd,6);
else addfile(&fd,5);
}
else if(fd.att&0x06) /* hidden or system file */
addfile(&fd,4);
else if(fd.att&0x01) /* read only file */
addfile(&fd,3);
else addfile(&fd,2); /* else normal user file */
}
}
}
char *makepath(buf,path,add) /* make a path name or template */
char *buf; /* storage for result */
char *path; /* starting path name */
char *add; /* text to add on the end */
{
extern char *makefnam(); /* filename fixer (optional) */
char *b = buf; /* string copy pointer */
char c = 0; /* one char of copy */
while(*path) /* copy over the path */
*b++ = c = *path++;
if(c) /* if any path at all */
if(c!='\\' && c!=':') /* if not path and not just disk */
*b++ = '\\'; /* then add a backslash */
while(*b++ = *add++); /* tack on the added part */
return makefnam(buf,"",buf); /* pass back fixed up name */
}
addfile(fd,grp) /* add a file to a group */
struct fds *fd; /* pointer to file data */
int grp; /* group to add file to */
{
num[grp][0] += 1; /* add to total */
size[grp][0] += fd->size;
if(fd->att&0x20) /* if file is not backed up */
{ num[grp][1] += 1; /* then add to changed total */
size[grp][1] += fd->size;
}
else /* else add to backed up total */
{ num[grp][2] += 1;
size[grp][2] += fd->size;
}
}
memory() /* report on memory */
{
struct {int scs,sss,sds,ses;} seg;
struct {int ax,bx,cx,dx,si,di,ds,es;} reg;
long core; /* total system memory */
long coreused; /* system memory in use */
segread(&seg); /* read our segment registers */
coreused = (long)seg.scs * 16; /* see how much is in use */
sysint(0x12,®,®); /* memory size determination */
core = (long)reg.ax * 1024; /* set total system memory */
printf("%9ld bytes total memory\n",core);
printf("%9ld bytes in use\n",coreused);
printf("%9ld bytes free\n",core-coreused);
}
int filedir(fd,name) /* get a directory entry */
struct fds *fd; /* data storage area */
char *name; /* filename template */
{
struct {int ax,bx,cx,dx,si,di,ds,es;} reg;
segread(®.si); /* set the segments */
bdos(0x1a,fd); /* set the transfer address */
reg.dx = name; /* point to search template */
reg.cx = 0x16; /* include special files */
if(fd->first) /* if this is our first call */
reg.ax = (0x4e << 8); /* then find first */
else reg.ax = (0x4f << 8); /* else find next */
fd->first = 0; /* next will not be first */
return !(sysint21(®,®)&1); /* return true if it works */
}
int volname(fd) /* get the volume entry */
struct fds *fd; /* data storage area */
{
struct {int ax,bx,cx,dx,si,di,ds,es;} reg;
char vnb[100]; /* volume name template buffer */
segread(®.si); /* set the segments */
bdos(0x1a,fd); /* set the transfer address */
makefnam("\\*.*",srchname,vnb); /* set proper drive in template */
reg.dx = vnb; /* point to volume template */
reg.cx = 0x08; /* volume label wanted */
reg.ax = (0x4e << 8); /* find first (only?) */
return !(sysint21(®,®)&1); /* return true if it works */
}
pdate(date) /* print a date */
struct /* structure of date word */
{ unsigned day : 5; /* day */
unsigned month : 4; /* month */
unsigned year : 7; /* year since 1980 */
} date; /* date to print */
{
static char *mname[] = /* list of month names */
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
printf("%s %2d, %04d ",mname[date.month-1],date.day,date.year+1980);
}
ptime(time) /* print a time */
struct /* structure of time word */
{ unsigned sec : 5; /* second pair */
unsigned minute : 6; /* minute */
unsigned hour : 5; /* hour */
} time; /* time to print */
{
int hh = time.hour; /* fudged time */
char ap = hh<12 ? 'a' : 'p'; /* am/pm marker */
if(hh>12) /* if afternoon */
hh -= 12; /* then convert to civilian */
if(hh==0) /* if in the wee hours */
hh = 12; /* then give as midnight */
printf("%2d:%02d%c ",hh,time.minute,ap);
}